<?php
namespace Admin\Controller;

class WechatsetController extends ComController
{
    public function index()
    {
        //$option = M('auth_rule')->order('o ASC')->select();
        //$option = $this->getMenu($option);
        $config = M('wx_set')->find();
        $this->assign('config', $config);
        $this->display('form');
    }

    public function edit($id = 0)
    {
        $id = intval($id);
        $m = M('auth_rule');
        $currentmenu = $m->where("id='$id'")->find();
        if (!$currentmenu) {
            $this->error('参数错误！');
        }

        $option = $m->order('o ASC')->select();
        $option = $this->getMenu($option);
        $this->assign('option', $option);
        $this->assign('currentmenu', $currentmenu);
        $this->display('form');
    }

    public function update()
    {
        // $id             = I('post.id', '', 'intval');
        $id                  = 1;
        $data['wxname']      = I('post.wxname', '', 'strip_tags');
        $data['wxurl']       = I('post.wxurl', '', 'validate_url');
        $data['wxsummary']   = I('post.wxsummary', '', 'strip_tags');
        $data['wxsuburl']    = I('post.wxsuburl','','validate_url');
        $data['wxappid']     = I('post.wxappid', '', 'strip_tags');
        $data['wxappsecret'] = I('post.wxappsecret', '', 'strip_tags');
        $data['wxtoken']     = I('post.wxtoken','', 'strip_tags');
        $data['wxmchid']     = I('post.wxmchid', '', 'strip_tags');
        $data['wxmchkey']    = I('post.wxmchkey', '', 'strip_tags');

        if (!$id) {
            $this->error('参数错误！');
        } else {
            // M('auth_rule')->data($data)->add();
            // addlog('新增菜单，名称：' . $data['title']);
        }

        $id = M('wx_set')->where('id=1')->getField('id');

        M('wx_set')->data($data)->where("id='{$id}'")->save();
        addlog('编辑微信设置' . $id);

        $this->success('微信设置操作成功！');
    }
}
